<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <html>
    <head>
        <title>SK43 TokTok Project</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <link rel="stylesheet" type="text/css" href="../css/index.css">
        <link rel="stylesheet" type="text/css" href="../css/join.css">
        <link rel="stylesheet" type="text/css" href="../css/button.css">
        <link rel="STYLESHEET" type="text/css" href="../dhtmlx/dhtmlxGrid/codebase/dhtmlxgrid.css">
        <link rel="STYLESHEET" type="text/css" href="../dhtmlx/dhtmlxGrid/codebase/dhtmlxgrid_skins.css">
        <script src="../dhtmlx/dhtmlxGrid/codebase/dhtmlxcommon.js"></script>
        <script src="../dhtmlx/dhtmlxGrid/codebase/dhtmlxgrid.js"></script>        
        <script src="../dhtmlx/dhtmlxGrid/codebase/dhtmlxgridcell.js"></script>
        <script src="../dhtmlx/dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_link.js"></script>
        <script src="../dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_srnd.js"></script>  
        <script src="../dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_nxml.js"></script>
        <script src="../dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_undo.js"></script>
        <script src="../dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_filter.js"></script>
        <script src="../dhtmlx/dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_acheck.js"></script> 
        <script src="../dhtmlx/dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_sub_row.js"></script>  
        <script src="../dhtmlx/dhtmlxDataProcessor/codebase/dhtmlxdataprocessor.js"></script>
      
        
        <script type="text/javascript">
            function enableSave(){
                document.getElementById('Save').disabled = false;
            }
            
            function enableDelete(){
                document.getElementById('Delete').disabled = false;
            }
            
            function AddCancel(){
                var CancelADD = "<a name='CancelADD' onclick='mygrid.selectRow(0);mygrid.deleteSelectedItem();ReturnADD();'><span>추가취소</span></a>"
                document.getElementById('ADD').innerHTML = CancelADD;
            }
            function ReturnADD(){
                var ReturnADD = "<a name='Add_Data' onclick='mygrid.addRow((new Date()).valueOf(),\",,,,,,,,,<?=$today?>,<?=$S_Members[LastName].$S_Members[FirstName]?>,0,0,\",0);enableSave();AddCancel();mygrid.selectRow(0);'><span>추가</span></a>" ;             
                document.getElementById('ADD').innerHTML = ReturnADD;
              }
            
            function disableButton(toggle){
                if(toggle == 'Disable'){
                    document.getElementById('Save').disabled = true;
                    document.getElementById('Delete').disabled = true;
                }else{
                    document.getElementById('Save').disabled = false;
                    document.getElementById('Delete').disabled = false;
                }
            }
            
            function deleteRow(){  
                var tmp = "선택된 셀을 삭제하시겠습니까?";
                if(confirm(tmp)){
                    mygrid.deleteSelectedItem();
                    myDataProcessor.sendData();
                    ReturnADD();    
                }else{
                    return;
                }
            } 
            
            function onBeforeUpdate(id,type){
                if(type == "updated"){
                    var tmp = "선택한  정보를 변경하시겠습니까?";
                    if(confirm(tmp)){ 
                        return true;
                    }else{
                        mygrid.doUndo();
                        return false;     
                    }
                }else if (type == "inserted"){
                    if(!CardName){
                        alert("데이터를 입력해주세요");
                        document.getElementById('Save').disabled = false;
                        mygrid.selectRow(0);    
                        return;
                    }else{
                        var tmp = "저장하시겠습니까?";
                        if(confirm(tmp)){
                            ReturnADD();
                            return true; 
                        }else{
                            return;
                        }
                    } 
                }else{
                   return true; 
                }
            }
            function save(){
                var id = mygrid.getSelectedRowId(); 
                var auth =mygrid.cellById(id,'c0');
                alert(id+":"+auth);
                //myDataProcessor.sendData();
            }                                      
        </script>
    </head>                                             
    <center>
    <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
        <form name="Management" method="POST">                
                    <table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td valign="top">
                                <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td>
                                        </td>
                                        <td valign="top">
                                       
                                        </td>
                                        <td valign="top">
                                            <br>
                                            <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td colspan="2">
                                                        <p><img src="../images/arrow.gif" border="0" height="12"><b>사원목록</b></p>
                                                    </td>
                                                </tr>                                                
                                                <tr height="2">
                                                    <td bgcolor="#86c1d9" colspan="2">
                                                    </td>
                                                </tr>
                                                <tr height="30">
                                                    <td class="inputbox">
                                                        <div id="employee_info" height="350" style="background-color:white;overflow:hidden"></div>      
                                                    </td>
                                                </tr>
                                                <tr height="1">
                                                    <td bgcolor="#cfdfe5" colspan="2">
                                                    </td>
                                                </tr>                                                                                               
                                            </table>
                                        </td>
                                    </tr>                                    
                                </table>   
                            </td>
                        </tr>
                        <tr height="30">
                            <td align="center">
                                <table>
                                <tBody id="Btn6">
                                    <tr>       
                                        <td>
                                            <div id="ADD">
                                            <a name="Add_Data" onclick="mygrid.addRow((new Date()).valueOf(),',,,,,,,,,<?=$today?>,<?=$S_Members[LastName].$S_Members[FirstName]?>,0,0',0);enableSave();mygrid.selectRow(0);AddCancel();"><span>추가</span></a>
                                            </div>
                                        </td>
                                        <td>
                                            <a name="Save" onclick="disableButton('Disable');save()" disabled><span>저장하기 </span></a>
                                        </td>
                                        <td>
                                            <a name="Delete" onclick="disableButton('Disable');deleteRow();enableDelete()" disabled><span>삭제하기 </span></a>
                                        </td>
                                    </tr>
                                </tBody>
                                </table>
                            </td>
                        </tr> 
                    </table>
            <script>
                 
            function afterClickAcheck(rowId){
            var id = mygrid.getRowIndex(rowId); 
            mygrid.selectRow(id);
            enableSave_Grid(rowId); 
            }
            
            function enableSave_Grid(rowId){
                document.getElementById('Save').disabled = false;
                document.getElementById('Delete').disabled = false;
                return rowId;
            }
            function checkEditeableCell(stage,rowId,cellInd){
                if(stage==0 && (cellInd != 8 || cellInd != 9)){
                    enableSave_Grid(rowId);
                }    
            }
         
            function onAfterUpdate(id,type,newId){
                switch(type){
                    case "update" :
                        alert("변경되었습니다."); 
                        disableButton('Disable');
                        break;
                    case "insert" :
                        alert("추가되었습니다.");
                        mygrid.clearAll(true);
                        mygrid.loadXML("get_search_employee_auth.jsp");
                        disableButton('Disable');
                        break;
                    case "delete" :
                        alert("삭제되었습니다.");
                        disableButton('Disable');
                        break;
                }
            }
            
            //추가시 각필드의 값들을 검사
            var CardName;  
            function checkValue(value,colName){
                CardName = value;
                return true;
            }
            //지점 설정                                                           
            function employee_info(){
                mygrid = new dhtmlXGridObject('employee_info');
                mygrid.setImagePath("../dhtmlx/dhtmlxGrid/codebase/imgs/");
                mygrid.setSkin("light"); 
                mygrid.setOnRowSelectHandler(enableSave_Grid);  //셀이 클릭됬을때 활성화
                mygrid.attachHeader("#text_filter,#select_filter,#text_filter,#select_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter");
                //mygrid.setOnRowDblClickedHandler(enableSave_Grid);
                //mygrid.setOnEditCellHandler(enableSave_Grid);         // 셀의 일부분이 클릭됬을때 활성화 
                //mygrid.enableEditEvents(true);  // 한번클릭으로 셀변경
                //mygrid.setOnCheckHandler(afterClickAcheck);   // 체크박스가 변경됬을때 활성화
               // mygrid.enableCollSpan(true); // 셀병합 활성화
                //mygrid.enableAutoHeigth(true); //셀높이 자동조절
                //mygrid.enableUndoRedo(); // 되돌림
                //mygrid.enableMultiselect(true); // 멀티 로 선택
                //mygrid.setNumberFormat("0,000.00",6);
                mygrid.init();
                mygrid.loadXML("get_search_employee_auth.jsp");
                
                //myDataProcessor = new dataProcessor("Update_CardInfo.php");
                //myDataProcessor.enableDataNames(true);
                //myDataProcessor.setVerificator(2,checkValue); 
                //myDataProcessor.setOnBeforeUpdateHandler(onBeforeUpdate);  
                //myDataProcessor.setOnAfterUpdate(onAfterUpdate);   
                //myDataProcessor.setUpdateMode("row");
                //myDataProcessor.setTransactionMode("POST");
                //myDataProcessor.init(mygrid);
            }
            employee_info();
                
            </script>             
        </body>
    </center>
</html>